﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UserControl_Taianhdaidien1 : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
      
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {

            UsersBLL userBLL = new UsersBLL();
            string tenTaiKhoan = "user";
            Users admin = userBLL.GetIUsers.GetUserByUsername(tenTaiKhoan);


           


            string strAdd = Server.MapPath("~\\Images\\") + FileUpload1.FileName;
            if (!System.IO.File.Exists(strAdd)) // Kiểm tra xem file này đã tồn tại hay chưa
            {
                FileUpload1.SaveAs(strAdd);
                
                lblFileType.Text = FileUpload1.PostedFile.ContentType;
                lblSize.Text = FileUpload1.PostedFile.ContentLength.ToString();
                lblCreateTime.Text = DateTime.Today.ToLocalTime().Date.ToString();
                Image1.ImageUrl = "~/Images/" + FileUpload1.FileName;



                // ImageUrl="~/Images/mysister5.jpg" Width="45px" />

                
                
            }
             UserProfiles UserPr = userBLL.GetIUserProfiles.GetUserProfileOfUser(admin);

            UserPr.User.Username = admin.Username;
            UserPr.Avatar = FileUpload1.FileName;
            bool kq = userBLL.GetIUserProfiles.UpdateAvatarUserProfiles(UserPr);
            try
            {
                if (kq == true)
                {
                   // Response.Redirect(Request.UrlReferrer.ToString());
                    Response.Write("<script>alert('thay doi anh thanh cong')</script>");
                   // Response.Redirect("ShowEditInforUserProfiles.aspx");
                }
                else
                {
                    Response.Write("<script>alert('thay doi anh khong thanh cong')</script>");


                }
            }
            catch
            {
            }

        }

    }
    protected void btnkhong_Click(object sender, EventArgs e)
    {
        FileUpload1.Controls.Clear();
    }
}